package de.hpi.generator.generator.distributors;

import de.hpi.generator.config.DistributionModel;
import de.hpi.generator.config.DistributionModelUNIFORM;
import de.hpi.generator.generator.storages.ValueSeriaInfo;
import de.hpi.generator.helpers.RandomSelector;
import java.util.Random;

public class UniformDistributor extends DataDistributor {

    protected int unique = 0;

    public UniformDistributor(int unique) {
        super();
        initClass(unique);
    }

    public UniformDistributor() {
        super();
        initClass(10);
    }

    /**
     * setup object with specialized params
     * 
     * @param aSpecializedDistributionModel
     *            specialized params
     */
    @Override
    protected void setupObjectWithSpecializedParams(DistributionModel aSpecializedDistributionModel) throws Exception {
        super.setupObjectWithSpecializedParams(aSpecializedDistributionModel);
        // convert common type of aSpecializedDistributionModel object to
        // specialized type
        DistributionModelUNIFORM aDistributionModelUNIFORM = (DistributionModelUNIFORM) aSpecializedDistributionModel;
        // setup distributor parameters
        this.initClass(aDistributionModelUNIFORM.unique);
    }

    @Override
    public String getName() {
        return "UNIFORM";
    }

    @Override
    public ValueSeriaInfo generateNextRandomValueSeriaInfo() throws Exception {
        int aRandomInteger = random.getRandomValue();
        int aRandomIntegerCount = this.getCountOfValue(aRandomInteger);

        return new ValueSeriaInfo(aRandomInteger, aRandomIntegerCount);
    }

    @Override
    public int getCountOfValue(int aValue) throws Exception {
        if(unique>aNumberOfValuesToGenerate)
            unique = aNumberOfValuesToGenerate;
        
        return super.aNumberOfValuesToGenerate / unique;
    }

    protected void initClass(int unique) {
        this.unique = unique;
        Random aRandom = new Random();
        this.random.calibrate(0, Integer.MAX_VALUE);
    }
    
        @Override
    public void setupRange(int aValuesCount) throws Exception {
        super.setupRange(aValuesCount);
       aAllValuesCount = aNumberOfValuesToGenerate;
    }
    

}
